﻿#include<iostream>
class T1;//声明类，不声明的话友元函数无法访问T1
class T {
	int hp;
	int mp;
	void GetHp() {
		T1 t1;
		t1.GetHp();//报错，T1没有声明T是友元类
		std::cout << hp << std::endl;
	}
	void GetMp() {
		std::cout << mp << std::endl;
	}
	friend class T1;
	friend void SetMp(T& t1, T1& t2);
	friend void SetHp(T& t1, T1& t2);
};
class T1 {
	int hp;
	int mp;
	void GetHp() {
		T t1;
		t1.GetHp();//因为T中声明了T1是友元类，所以T1能访问T的全部成员
		std::cout << hp << std::endl;
	}
	void GetMp() {
		std::cout << mp << std::endl;
	}

	friend void SetMp(T& t1, T1& t2);//声明SetMp为友元函数
	friend void SetHp(T& t1, T1& t2);//声明SetHp为友元函数
};
void SetMp(T& t1, T1& t2) {
	t1.mp = 2500;
	t1.GetMp();
}
void SetHp(T& t1, T1& t2) {
	t1.hp = 2500;
	t1.GetHp();
}
int main() {

}